package com.winning.sx.microframework.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.winning.sx.microframework.common.support.Ret;
import com.winning.sx.microframework.model.exception.CustomException;
import com.winning.sx.microframework.model.message.AjaxDataResponseMessage;
import com.winning.sx.microframework.service.GenericApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * 例子
 */
@RestController
@RequestMapping("/api")
public class GenericApiHandler {

    @Autowired
    private GenericApiService genericApiService;

    @RequestMapping("/")
    public Ret api(String data){
        return genericApiService.send(data,"127.0.0.1");
    }

    @ResponseBody
    @RequestMapping(value = {"/apiTest"})
    public AjaxDataResponseMessage apiTest(HttpServletRequest request) {
        AjaxDataResponseMessage ajaxTableResponseMessage = new AjaxDataResponseMessage();
        try {
            return genericApiService.send("{\"interfaceCode\":\"3.1.16\",\"serverName\":\"his\",\"name\":\"交住院押金\"}",
                    GenericApiService.getIpAddress(request));
        } catch (Exception e) {
            ajaxTableResponseMessage.setSuccess(false);
            ajaxTableResponseMessage.setErrorMsg(e.getMessage());
        }
        return ajaxTableResponseMessage;
    }
    }

